/*
 * Propiedades.java
 *
 * Created on 28 de mayo de 2007, 09:22 AM
 */
package ig.metrica.ui;

import ig.formato.gui.app.DConfiguracion;
import ig.util.LoadProperties;
import ig.util.TripleDESEncryption;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
import javax.swing.JOptionPane;

/**
 *
 * @author jsanchez
 */
public class PropiedadesJDBC extends javax.swing.JDialog {

    public static final String RUTA_METRICADB_DS_PROPERTIES = "server/METRICADB-DS.properties";
    public static final String RUTA_METRICADW_DS_PROPERTIES = "server/METRICADW-DS.properties";
    public static final String RUTA_METRICADA_DS_PROPERTIES = "server/METRICADA-DS.properties";
    private Properties propiedadesDA = null;
    private Properties propiedadesDB = null;
    private Properties propiedadesDW = null;
    private DConfiguracion dc = null;
    private static String KEY_TRIPLE_DES = "informaciongerencial.com";
    
    private void ini() {
        try {
            propiedadesDW = LoadProperties.loadPropertiess(RUTA_METRICADW_DS_PROPERTIES);
        } catch (Exception e) {
            propiedadesDW = new Properties();
            e.printStackTrace();
        }
        try {
            propiedadesDB = LoadProperties.loadPropertiess(RUTA_METRICADB_DS_PROPERTIES);
        } catch (Exception e) {
            propiedadesDB = new Properties();
            e.printStackTrace();
        }
        try {
            propiedadesDA = LoadProperties.loadPropertiess(RUTA_METRICADA_DS_PROPERTIES);
        } catch (Exception e) {
            propiedadesDA = new Properties();
            e.printStackTrace();
        }
        try {
            dc = new DConfiguracion(null, false);
            dc.setVisible(false);
            this.jTabbedPane1.add("IGFormato", dc.getTabbedPane(0));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Creates new form Propiedades
     */
    public PropiedadesJDBC(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        ini();
        this.driverDA.setText(propiedadesDA.getProperty("driver"));
        this.driverDB.setText(propiedadesDB.getProperty("driver"));
        this.driverDW.setText(propiedadesDW.getProperty("driver"));

        this.urlDA.setText(propiedadesDA.getProperty("url"));
        this.urlDB.setText(propiedadesDB.getProperty("url"));
        this.urlDW.setText(propiedadesDW.getProperty("url"));

        this.usuarioDA.setText(propiedadesDA.getProperty("user"));
        this.usuarioDB.setText(propiedadesDB.getProperty("user"));
        this.usuarioDW.setText(propiedadesDW.getProperty("user"));
        
        try {
            this.claveDA.setText(TripleDESEncryption.decrypt(propiedadesDA.getProperty("password"), KEY_TRIPLE_DES));
        } catch (Exception e) {
            this.claveDA.setText(propiedadesDA.getProperty("password"));
        }
        try {
            this.claveDB.setText(TripleDESEncryption.decrypt(propiedadesDB.getProperty("password"), KEY_TRIPLE_DES));
        } catch (Exception e) {
            this.claveDB.setText(propiedadesDB.getProperty("password"));
        }
        try {
            this.claveDW.setText(TripleDESEncryption.decrypt(propiedadesDW.getProperty("password"), KEY_TRIPLE_DES));
        } catch (Exception e) {
            this.claveDW.setText(propiedadesDW.getProperty("password"));
        }
        
        java.awt.Dimension dimensionScreen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Rectangle dimensionPantalla = getBounds();
        setLocation((dimensionScreen.width - (dimensionPantalla.width - 620)) / 2, (dimensionScreen.height - dimensionPantalla.height) / 2);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        Aceptar = new javax.swing.JButton();
        Cancelar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        driverDB = new javax.swing.JTextField();
        urlDB = new javax.swing.JTextField();
        usuarioDB = new javax.swing.JTextField();
        claveDB = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        driverDW = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        urlDW = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        usuarioDW = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        claveDW = new javax.swing.JPasswordField();
        jButton2 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        driverDA = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        urlDA = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        usuarioDA = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        claveDA = new javax.swing.JPasswordField();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.title")); // NOI18N
        setModal(true);
        setResizable(false);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel1.text")); // NOI18N

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel2.text")); // NOI18N

        Aceptar.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.Aceptar.text")); // NOI18N
        Aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AceptarActionPerformed(evt);
            }
        });

        Cancelar.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.Cancelar.text")); // NOI18N
        Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelarActionPerformed(evt);
            }
        });

        jLabel3.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel3.text")); // NOI18N

        jLabel4.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel4.text")); // NOI18N

        jLabel5.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel5.text")); // NOI18N

        jLabel6.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel6.text")); // NOI18N

        driverDB.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.driverDB.text")); // NOI18N

        urlDB.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.urlDB.text")); // NOI18N

        usuarioDB.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.usuarioDB.text")); // NOI18N

        claveDB.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.claveDB.text")); // NOI18N

        jButton1.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jButton1.text")); // NOI18N
        jButton1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jLabel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(driverDB)
                            .add(urlDB)
                            .add(usuarioDB)
                            .add(claveDB, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 75, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(driverDB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(urlDB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(usuarioDB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(claveDB)
                    .add(jLabel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton1)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jLabel7.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel7.text")); // NOI18N

        driverDW.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.driverDW.text")); // NOI18N

        jLabel8.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel8.text")); // NOI18N

        urlDW.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.urlDW.text")); // NOI18N

        jLabel9.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel9.text")); // NOI18N

        usuarioDW.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.usuarioDW.text")); // NOI18N

        jLabel10.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel10.text")); // NOI18N

        claveDW.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.claveDW.text")); // NOI18N

        jButton2.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jButton2.text")); // NOI18N
        jButton2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jLabel9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(driverDW)
                            .add(urlDW)
                            .add(usuarioDW)
                            .add(claveDW, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(driverDW, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel8)
                    .add(urlDW, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel9)
                    .add(usuarioDW, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(claveDW)
                    .add(jLabel10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton2)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

        jLabel11.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel11.text")); // NOI18N

        driverDA.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.driverDA.text")); // NOI18N

        jLabel12.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel12.text")); // NOI18N

        urlDA.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.urlDA.text")); // NOI18N

        jLabel13.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel13.text")); // NOI18N

        usuarioDA.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.usuarioDA.text")); // NOI18N

        jLabel14.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jLabel14.text")); // NOI18N

        claveDA.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.claveDA.text")); // NOI18N

        jButton3.setText(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jButton3.text")); // NOI18N
        jButton3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jLabel13, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel11, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel12, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(driverDA)
                            .add(urlDA)
                            .add(usuarioDA)
                            .add(claveDA, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)))
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(driverDA, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel12)
                    .add(urlDA, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel13)
                    .add(usuarioDA, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(claveDA)
                    .add(jLabel14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton3)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(PropiedadesJDBC.class, "PropiedadesJDBC.jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jSeparator2)
                            .add(jSeparator1)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jTabbedPane1))
                        .addContainerGap())
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(Aceptar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(28, 28, 28)
                        .add(Cancelar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 77, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(157, 157, 157))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(Cancelar)
                    .add(Aceptar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void AceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AceptarActionPerformed
        propiedadesDA.setProperty("driver", this.driverDA.getText().trim());
        propiedadesDA.setProperty("url", this.urlDA.getText().trim());
        propiedadesDA.setProperty("user", this.usuarioDA.getText().trim());
        propiedadesDA.setProperty("password", new String(this.claveDA.getPassword()));
        try {
            String _clave = TripleDESEncryption.encrypt(propiedadesDA.getProperty("password"), KEY_TRIPLE_DES);
            propiedadesDA.setProperty("password", _clave);
        } catch (Exception e) {
        }
        LoadProperties.storePropertiess(propiedadesDA, "server/METRICADA-DS.properties", "Configuracion de coenxiones metrica DA");

        propiedadesDB.setProperty("driver", this.driverDB.getText().trim());
        propiedadesDB.setProperty("url", this.urlDB.getText().trim());
        propiedadesDB.setProperty("user", this.usuarioDB.getText().trim());
        propiedadesDB.setProperty("password", new String(this.claveDB.getPassword()));
        try {
            String _clave = TripleDESEncryption.encrypt(propiedadesDB.getProperty("password"), KEY_TRIPLE_DES);
            propiedadesDB.setProperty("password", _clave);
        } catch (Exception e) {
        }
        LoadProperties.storePropertiess(propiedadesDB, "server/METRICADB-DS.properties", "Configuracion de coenxiones metrica DB");

        propiedadesDW.setProperty("driver", this.driverDW.getText().trim());
        propiedadesDW.setProperty("url", this.urlDW.getText().trim());
        propiedadesDW.setProperty("user", this.usuarioDW.getText().trim());
        propiedadesDW.setProperty("password", new String(this.claveDW.getPassword()));
        try {
            String _clave = TripleDESEncryption.encrypt(propiedadesDW.getProperty("password"), KEY_TRIPLE_DES);
            propiedadesDW.setProperty("password", _clave);
        } catch (Exception e) {
        }
        LoadProperties.storePropertiess(propiedadesDW, "server/METRICADW-DS.properties", "Configuracion de coenxiones metrica DW");

        try {
            dc.guardarDatosBaseDeDatosMaestra();
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.dispose();
    }//GEN-LAST:event_AceptarActionPerformed

    private void CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_CancelarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        test("Metrica DB", this.driverDB.getText(), this.urlDB.getText(), this.usuarioDB.getText(), new String(this.claveDB.getPassword()));
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        test("Metrica DW", this.driverDW.getText(), this.urlDW.getText(), this.usuarioDW.getText(), new String(this.claveDW.getPassword()));
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        test("Metrica DA", this.driverDA.getText(), this.urlDA.getText(), this.usuarioDA.getText(), new String(this.claveDA.getPassword()));
    }//GEN-LAST:event_jButton3ActionPerformed

    private void test(String DB, String driver, String url, String user, String clave) {
        Connection conn = null;
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, clave);
            JOptionPane.showMessageDialog(this, "Acceso a " + DB + " OK");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage() + "\n[" + e + "]", "Error", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } finally {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new Propiedades(new javax.swing.JFrame(), true).setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Aceptar;
    private javax.swing.JButton Cancelar;
    private javax.swing.JPasswordField claveDA;
    private javax.swing.JPasswordField claveDB;
    private javax.swing.JPasswordField claveDW;
    private javax.swing.JTextField driverDA;
    private javax.swing.JTextField driverDB;
    private javax.swing.JTextField driverDW;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField urlDA;
    private javax.swing.JTextField urlDB;
    private javax.swing.JTextField urlDW;
    private javax.swing.JTextField usuarioDA;
    private javax.swing.JTextField usuarioDB;
    private javax.swing.JTextField usuarioDW;
    // End of variables declaration//GEN-END:variables
}
